unit HashView_U;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, AcroMultiDD, AcroMultiReplacer,AcroMultiScreen;

type
  TFormHashView = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Memo1: TMemo;
    Button3: TButton;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure AcroMultiReplacer1BeforeReplace(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    FMS:TMemoryStream;
    procedure ReaderError(Reader: TReader; const Message: string; var Handled: Boolean);
    procedure ReaderOnMethod(Reader: TReader; const MethodName: string;
      var Address: Pointer; var Error: Boolean);
    procedure ReaderOnAncestorNotFound(Reader: TReader; const ComponentName: string;
      ComponentClass: TPersistentClass; var Component: TComponent);
    procedure ReaderFindComponentClass(Reader: TReader; const ClassName: string;
      var ComponentClass: TComponentClass);
  public
    { Public declarations }
    constructor Create(AOwner:TComponent);override;
    destructor Destroy;override;
  end;

var
  FormHashView: TFormHashView;

implementation

uses DemoDM_U;

{$R *.dfm}

procedure TFormHashView.Button1Click(Sender: TObject);
begin
  Edit1.Text:=InttoStr(MultiDM.AcroMultiStreamDD_GUI.DataList.HashSize);
  Edit2.Text:=InttoStr(MultiDM.AcroMultiStreamDD_GUI.DataList.GetHashCount);
  Edit3.Text:=InttoStr(MultiDM.AcroMultiStreamDD_GUI.DataList.Count);
  Edit4.Text:=Edit2.Text+'/'+Edit3.Text+'='+FloatToStr(MultiDM.AcroMultiStreamDD_GUI.DataList.GetHashCount/
    MultiDM.AcroMultiStreamDD_GUI.DataList.Count);
end;

procedure TFormHashView.Button2Click(Sender: TObject);
var
  R:TReader;
  i:integer;
begin
//  AcroMultiReplacer1.OwnerOption.SystemCodePage:=false;
//  AcroMultiReplacer1.OwnerOption.CodePage:='950';
  ShowMessage(Button3.Caption);
  FMS.Position:=0;
  R:=TReader.Create(FMS,$1000);
  try
    R.OnError:=ReaderError;
    R.OnFindMethod:=ReaderOnMethod;
    R.OnAncestorNotFound:=ReaderOnAncestorNotFound;
    R.OnFindComponentClass:=ReaderFindComponentClass;
    R.IgnoreChildren:=true;
    R.Root:=Button3;
    R.BeginReferences;
    R.Position:=0;
    R.ReadSignature;
    R.ReadComponent(Button3);
//    TComponent_Temp(ToolBar_Dictionary).GetChildren(ComponentGetChild,);
//      R.FixupReferences;
    R.EndReferences;
    ShowMessage(Button3.Caption);
  finally
    R.Free;
  end;
  ReplaceComLanguage(AcroDDStorage.FindDD(AcroMultiScreen.ScreenStorage.DefaultReplaceOption.DDName),self,'950','0',true,true,false,nil,true);
end;

procedure TFormHashView.AcroMultiReplacer1BeforeReplace(Sender: TObject);
var
  W:TWriter;
  MS:TMemoryStream;
  B:integer;
begin
  FMS.Clear;
  W:=TWriter.Create(FMS,$1000);
  try
    W.IgnoreChildren:=false;
    W.Root:=Button3;
    W.WriteSignature;
 {   B:=$F0;
    W.WriteInteger(B);
    B:=$01;
    W.WriteInteger(B);}
    W.WriteComponent(Button3);
    W.FlushBuffer;
 {   MS:=TMemoryStream.Create;
    try
      FMS.Position:=0;
      Classes.ObjectBinaryToText(FMS,MS);
      MS.Position:=0;
      Memo1.Lines.LoadFromStream(MS);
    finally
      MS.Free;
    end; }
  finally
    W.Free;
  end;
end;

procedure TFormHashView.ReaderError(Reader: TReader; const Message: string;
  var Handled: Boolean);
begin
  Handled:=true;
end;

procedure TFormHashView.ReaderFindComponentClass(Reader: TReader;
  const ClassName: string; var ComponentClass: TComponentClass);
var
  i:integer;
begin
  if ComponentClass=nil then
    for i:=0 to ComponentCount-1 do
    if Components[i].ClassName=ClassName then
    begin
      ComponentClass:=TComponentClass(Components[i].ClassType);
      break;
    end;
end;

procedure TFormHashView.ReaderOnAncestorNotFound(Reader: TReader;
  const ComponentName: string; ComponentClass: TPersistentClass;
  var Component: TComponent);
begin
  Component:=Self.FindComponent(ComponentName);
end;

procedure TFormHashView.ReaderOnMethod(Reader: TReader;
  const MethodName: string; var Address: Pointer; var Error: Boolean);
begin
  Error:=false;
end;

constructor TFormHashView.Create(AOwner: TComponent);
begin
  FMS:=TMemoryStream.Create;
  inherited;
end;

destructor TFormHashView.Destroy;
begin
  FMS.Free;
  inherited;
end;

procedure TFormHashView.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action:=caFree;
end;

end.
